package com.itheima.health.controller;


import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lenovo
 * @Date: 14:03 2021/5/10
 * @Parms
 * @ReturnType:
 * @Description:对会员的管理（增删改查）
 */
@RestController
@Slf4j
@RequestMapping("member")
@CrossOrigin
public class MemberController {

    @DubboReference
    private MemberService memberService;

    @GetMapping("findpage")
    public Result finaPage(QueryPageBean queryPageBean) {
        PageResult page = memberService.findPage(queryPageBean);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, page);
    }

    @PostMapping("add")
    public Result add(@RequestBody Member member) {
        memberService.add(member);
        return new Result(true, MessageConst.ADD_CHECKITEM_SUCCESS);
    }

    @PostMapping("delete")
    public Result delete(Integer id) {
        memberService.delete(id);
        return new Result(true, MessageConst.DELETE_CHECKITEM_SUCCESS);
    }

    @GetMapping("findById")
    public Result findById(Integer id) {
        Member member = memberService.findById(id);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, member);
    }

    @PostMapping("edit")
    public Result edit(@RequestBody Member member) {
        memberService.edit(member);
        return new Result(true, MessageConst.EDIT_CHECKITEM_SUCCESS);
    }

    @GetMapping("findAll")
    public Result findAll() {
        List<Member> all = memberService.findAll();
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, all);
    }
}
